<?php
namespace Home\Controller;
use Think\Controller;
class LotteryController extends Controller {
	public function _initialize(){
		$uid = $_SESSION['user_id'];
		if(empty($uid)) {
			$this->display("Index/login");
		}
	}
    //获取 接口数据
	static function get_data($a){
		$url = "http://a.apiplus.net/newly.do?token=7684e585c2f14db0&code=".$a."&format=json&rows=10";
		$ch = curl_init(); 
		curl_setopt ($ch, CURLOPT_URL,$url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		$file_contents = curl_exec($ch);
		curl_close($ch);
		$data = json_decode($file_contents,true);
		$arr = $data["data"];
		foreach($arr as $k=>$v){
			$arr[$k]['ocode'] = explode(",",$v['opencode']);
		}
		foreach($arr as $k=>$v){
			$m = 0;
			foreach($v['ocode'] as $kc=>$vc){
				$m+=$vc;
			}
			$arr[$k]['total'] = $m;
			if($m>=3 && $m<=10){
				$arr[$k]['size'] = '1';//小
			}if($m>=11 && $m<=18){
				$arr[$k]['size'] = '2';//大
			}
			if($m%2!=0){
				$arr[$k]['attr'] = '1';//单
			}else{
				$arr[$k]['attr'] = '2';//双
			}
		}

		return $arr;
	}
	public function get_time(){
		$id = I("id");
		$data = M('lottery_class')->where("id=$id")->find();
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$t = $ti * 1000;
		echo $t;
	}

	public function get_time22(){
		$id = I("id");
		$data = M('lottery_class')->where("id=$id")->find();
		$s2 = date("Y-m-d")." ".$data['etime'];
		$ti = strtotime($s2) - time();
		$t = $ti * 1000;
		echo $t;
	}

	//当前 期数
	public function upd_issue(){
		$data['current_issue'] = I('na2');
		$data['coming_issue'] = I('na');
		$id = I("id");
		M('lottery_class')->where("id=$id")->save($data);
		$dat['current_issue'] = substr(I('na2'),4);
		$dat['coming_issue'] = substr(I('na'),4);
		echo json_encode($dat);
	}
	public function k3_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("k3")->find();
		$res = M("rebate_k3")->find();
		$k3 = array(
			($lv['k3']-0)*0.01+$res['daxiao'],
			($lv['k3']-0)*2.16+$res['he3'],
			($lv['k3']-0)*0.72+$res['he4'],
			($lv['k3']-0)*0.36+$res['he5'],
			($lv['k3']-0)*0.21+$res['he6'],
			($lv['k3']-0)*0.14+$res['he7'],
			($lv['k3']-0)*0.10+$res['he8'],
			($lv['k3']-0)*0.09+$res['he9'],
			($lv['k3']-0)*0.08+$res['he10'],
			($lv['k3']-0)*0.36+$res['t3tx'],
			($lv['k3']-0)*2.16+$res['t3dx'],
			($lv['k3']-0)*0.36+$res['bt3'],
			($lv['k3']-0)*0.09+$res['t3lh'],
			($lv['k3']-0)*0.15+$res['ertfx'],
			($lv['k3']-0)*0.72+$res['ertdx'],
			($lv['k3']-0)*0.07+$res['bt2'],
		);
		$pos=array_search(max($k3),$k3);
		$this->assign("max",$k3[$pos]);
		$pos1=array_search(min($k3),$k3);
		$this->assign("min",$k3[$pos1]);
		$this->assign("k3",$k3);
	}
	public function k3_comm2(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("k3")->find();
		$res = M("rebate_k3")->find();
		$k3 = array(
			'大' => ($lv['k3']-0)*0.01+$res['daxiao'],
			'小' => ($lv['k3']-0)*0.01+$res['daxiao'],
			'单' => ($lv['k3']-0)*0.01+$res['daxiao'],
			'双' => ($lv['k3']-0)*0.01+$res['daxiao'],
			'3' => ($lv['k3']-0)*2.16+$res['he3'],
			'18' => ($lv['k3']-0)*2.16+$res['he3'],
			'4' => ($lv['k3']-0)*0.72+$res['he4'],
			'17' => ($lv['k3']-0)*0.72+$res['he4'],
			'5' => ($lv['k3']-0)*0.36+$res['he5'],
			'16' => ($lv['k3']-0)*0.36+$res['he5'],
			'6' => ($lv['k3']-0)*0.21+$res['he6'],
			'15' => ($lv['k3']-0)*0.21+$res['he6'],
			'7' => ($lv['k3']-0)*0.14+$res['he7'],
			'14' => ($lv['k3']-0)*0.14+$res['he7'],
			'8' => ($lv['k3']-0)*0.10+$res['he8'],
			'13' => ($lv['k3']-0)*0.10+$res['he8'],
			'9' => ($lv['k3']-0)*0.09+$res['he9'],
			'12' => ($lv['k3']-0)*0.09+$res['he9'],
			'10' => ($lv['k3']-0)*0.08+$res['he10'],
			'11' => ($lv['k3']-0)*0.08+$res['he10']
		);
		return $k3;
	}
	//江苏快3
	public function jiangsu(){
		$arr = $this->get_data("jsk3");

		$uid = $_SESSION['user_id'];
		if($uid){
			self::k3_comm();
			$data = M('lottery_class')->where("id=1")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];

			$ti = $jie-time();

			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_add")->where("uid = $uid and lotteryclass=1")->order("id desc")->limit(4)->select();

			$tt = $data['jian_time']*60-$data['feng_time'];

			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=1") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=1") ->save($d);
			}

			$da = M('lottery_class') ->where("id=1") ->find();

			$end = date("Ymd")."082";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	//北京快3
	public function beijing(){
		$arr = $this->get_data("bjk3");
		$uid = $_SESSION['user_id'];
		if($uid){
			self::k3_comm();
			$data = M('lottery_class')->where("id=5")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_add")->where("uid = $uid and lotteryclass=5")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$nu = $arr[0]['expect']+1;
				$nn = "00000".$nu;
				$cn = substr($nn,-6);
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $cn;
				M('lottery_class') ->where("id=5") ->save($d);

				$nu1 = $arr[0]['expect']+2;
				$nn1 = "00000".$nu1;
				$cn1 = substr($nn1,-6);
			}else{
				$nu = $arr[0]['expect']+1;
				$nn = "00000".$nu;
				$cn = substr($nn,-6);
				$nu1 = $arr[0]['expect']+2;
				$nn1 = "00000".$nu1;
				$cn1 = substr($nn1,-6);
				$d['coming_issue'] = $cn;
				$d['current_issue'] = $cn1;
				M('lottery_class') ->where("id=5") ->save($d);
			}
			$da = M('lottery_class') ->where("id=5") ->find();
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->assign("cn",$cn);
			$this->assign("cn1",$cn1);
			$this->display();
		}
	}
	//安徽快3
	public function anhui(){
		$arr = $this->get_data("ahk3");
		$uid = $_SESSION['user_id'];
		if($uid){
			self::k3_comm();
			$data = M('lottery_class')->where("id=2")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_add")->where("lotteryclass=2")->order("id desc")->limit(4)->select();
			
			$tt = $data['jian_time']*60-$data['feng_time'];
		
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=2") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=2") ->save($d);
			}
			$da = M('lottery_class') ->where("id=2") ->find();
			$end = date("Ymd")."080";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	//河北快3
	public function hebei(){
		$arr = $this->get_data("hebk3");
		$uid = $_SESSION['user_id'];
		if($uid){
			self::k3_comm();
			$data = M('lottery_class')->where("id=9")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_add")->where("uid = $uid and lotteryclass=9")->order("id desc")->limit(4)->select();
			
			$tt = $data['jian_time']*60-$data['feng_time'];
		
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=9") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=9") ->save($d);
			}
			$da = M('lottery_class') ->where("id=9") ->find();
			$end = date("Ymd")."081";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	//广西快3
	public function guangxi(){
		$arr = $this->get_data("gxk3");
		$uid = $_SESSION['user_id'];
		self::k3_comm();
		$data = M('lottery_class')->where("id=3")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_add")->where("uid = $uid and lotteryclass=3")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=3") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=3") ->save($d);
		}
		$da = M('lottery_class') ->where("id=3") ->find();
		$end = date("Ymd")."078";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//湖北快3
	public function hubei(){
		$arr = $this->get_data("hubk3");
		$uid = $_SESSION['user_id'];
		self::k3_comm();
		$data = M('lottery_class')->where("id=4")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_add")->where("uid = $uid and lotteryclass=4")->order("id desc")->limit(4)->select();
		
		$tt = $data['jian_time']*60-$data['feng_time'];
	
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=4") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=4") ->save($d);
		}
		$da = M('lottery_class') ->where("id=4") ->find();
		$end = date("Ymd")."078";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//甘肃快3
	public function gansu(){
		$arr = $this->get_data("gsk3");
		$uid = $_SESSION['user_id'];
		self::k3_comm();
		$data = M('lottery_class')->where("id=10")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_add")->where("uid = $uid and lotteryclass=10")->order("id desc")->limit(4)->select();
		
		$tt = $data['jian_time']*60-$data['feng_time'];
	
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=10") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=10") ->save($d);
		}
		$da = M('lottery_class') ->where("id=10") ->find();
		$end = date("Ymd")."072";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//上海快3
	public function shanghai(){
		$arr = $this->get_data("shk3");
		$uid = $_SESSION['user_id'];
		self::k3_comm();
		$data = M('lottery_class')->where("id=11")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_add")->where("uid = $uid and lotteryclass=11")->order("id desc")->limit(4)->select();
		
		$tt = $data['jian_time']*60-$data['feng_time'];
	
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=11") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=11") ->save($d);
		}
		$da = M('lottery_class') ->where("id=11") ->find();
		$end = date("Ymd")."082";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//贵州快3
	public function guizhou(){
		$arr = $this->get_data("gzk3");
		$uid = $_SESSION['user_id'];
		self::k3_comm();
		$data = M('lottery_class')->where("id=12")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_add")->where("uid = $uid and lotteryclass=12")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=12") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=12") ->save($d);
		}
		$da = M('lottery_class') ->where("id=12") ->find();
		$end = date("Ymd")."078";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//吉林快3
	public function jilin(){
		$arr = $this->get_data("jlk3");
		$uid = $_SESSION['user_id'];
		self::k3_comm();
		$data = M('lottery_class')->where("id=13")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_add")->where("uid = $uid and lotteryclass=13")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=13") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=1") ->save($d);
		}
		$da = M('lottery_class') ->where("id=13") ->find();
		$end = date("Ymd")."079";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//添加 投注
	public function adds(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'lotteryclass' => Admin_post('lottery_class_id'),
			'issue' => Admin_post('issue'),
			'pour' => Admin_post('zhus'),
			'money' => Admin_post('mons'),
			'numbers' => "TZ".date(md).time(),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("money,yq_code")->find();
		if($mm['money'] < $search['money']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['money']);
		}
		$ids = M('lottery_add')->add($search);
		$cc = self::k3_comm2();
		$dat = array();
		$arr = I('ty_name');
		$vs = I('vls');
		$pr = I('pours');
		$pm = I('per_money');
		$narr = explode(",",str_replace(" ",",",rtrim($vs)));
		//1和值2三同号通选3三同号单选4三不同号5三连号通选6二同号复选7二同号单选8二不同号
		if($arr=='1'){
			foreach($narr as $k=>$v){
				$am[] = $cc[$v];
			}
		}else if($arr=='2'){
			$am = $k3['9'];
		}else if($arr=='3'){
			$am = $k3['10'];
		}else if($arr=='4'){
			$am = $k3['11'];
		}else if($arr=='5'){
			$am = $k3['12'];
		}else if($arr=='6'){
			$am = $k3['13'];
		}else if($arr=='7'){
			$am = $k3['14'];
		}else if($arr=='8'){
			$am = $k3['15'];
		}
		foreach($narr as $k=>$v){
			$dat[$k]['lottery_add_id'] = $ids;
			$dat[$k]['type'] = $arr;
			$dat[$k]['cal'] = $v;//选择的值
			$dat[$k]['pours'] = 1;//买了几注
			$dat[$k]['moneys'] = $pm;//每注 多少钱
			if(is_array($am)){
				$dat[$k]['con_money'] = $pm * $am[$k];//可中金额
			}else{
				$dat[$k]['con_money'] = $pm * $am;//可中金额
			}
		}
		$res = M("lottery_add_detail")->addAll($dat);
		if($res){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,k3")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("k3")->find();//上级返点
					$momm = (($c1['k3'] - $cc['k3'])/100) * $search['money'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();

					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['money'];
				$cp['ky_money'] = $mm['money'] - $search['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);	
			}
			echo 1;
		}else{
			echo 0;
		}
	}

	static function get_data2($a){
		$url = "http://a.apiplus.net/newly.do?token=7684e585c2f14db0&code=".$a."&format=json&rows=10";
		$ch = curl_init(); 
		curl_setopt ($ch, CURLOPT_URL,$url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		$file_contents = curl_exec($ch);
		curl_close($ch);
		$data = json_decode($file_contents,true);
		$arr = $data["data"];
		foreach($arr as $k=>$v){
			$arr[$k]['otime'] = date("H:i:s",$v['opentimestamp']);
			$arr[$k]['ocode'] = explode(",",$v['opencode']);
		}
		return $arr;
	}
	public function pk10_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("pk10")->find();
		$res = M("rebate_pk10")->find();
		$pk10 = array(
			($lv['pk10']-0)*0.20+$res['dwd'],
			($lv['pk10']-0)*604.80+$res['q5fs'],
			($lv['pk10']-0)*604.80+$res['q5ds'],
			($lv['pk10']-0)*100.80+$res['q4fs'],
			($lv['pk10']-0)*100.80+$res['q4ds'],
			($lv['pk10']-0)*14.40+$res['q3fs'],
			($lv['pk10']-0)*14.40+$res['q3ds'],
			($lv['pk10']-0)*1.80+$res['q2fs'],
			($lv['pk10']-0)*1.80+$res['q2ds'],
			($lv['pk10']-0)*0.2+$res['q1fs']
		);
		$this->assign("pk10",$pk10);
	}
	//pk10
	public function pk10(){
		$uid = $_SESSION['user_id'];
		if($uid){
			self::pk10_comm();
			$arr = $this->get_data2("bjpk10");
			foreach($arr as $kk=>$vv){
				$arr[$kk]['ooco'] = str_replace(","," ",$vv['opencode']);
			}
			$data = M('lottery_class')->where("id=21")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_pk10")->where("uid = $uid")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=21") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=21") ->save($d);
			}
			$da = M('lottery_class') ->where("id=21") ->find();
			foreach($arr as $ka=>$va){
				$arr[$ka]['ooc'] = str_replace("+",",",$va['opencode']);
			}
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	public function adds_pk10(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'issue' => Admin_post('issue'),
			'lotteryclass' => '21',
			'pours' => Admin_post('pour'),
			'money' => Admin_post('money'),
			'numbers' => "TZ".date(md).time(),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['money']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['money']);
		}
		$ids = M('lottery_pk10')->add($search);
		$dat = array();
		$arr = I('ty');
		$arr2 = I('fu');
		$vs = I('cal');
		$pr = I('pours');
		$be = I('bei');
		$zh = I('zhong_money');
		foreach($arr as $k=>$v){
			$dat[$k]['lottery_pk10_id'] = $ids;
			$dat[$k]['type'] = $v;
			$dat[$k]['m_type'] = $arr2[$k];
			$dat[$k]['cal'] = $vs[$k];//选择的值
			$dat[$k]['pours'] = $pr[$k];//买了几注
			$dat[$k]['bei'] = $be[$k];//多少倍
		//	$dat[$k]['unit'] = $un[$k];//单位
			$dat[$k]['zo_money'] = $zh[$k] * $be[$k];//可中金额
		}
		$ress = M("lottery_pk10_detail")->addAll($dat);
		if($ress){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,pk10")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("pk10")->find();//上级返点
					$momm = (($c1['pk10'] - $cc['pk10'])/100) * $search['money'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['money'];
				$cp['ky_money'] = $mm['money'] - $search['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);
			}
			echo 1;
		}else{
			echo 0;
		}
	}
	public function pk10_zhui_add(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'numbers' => "TZ".date(md).time(),
			'start_num' => Admin_post('issue'),
			'lotteryclass' => '21',
			'qishus' => Admin_post('qis'),
			'zhus' => Admin_post('pour'),
			'moneys' => Admin_post('money'),
			'is_ting' => Admin_post('ting'),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['moneys']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['moneys']);
		}
		$ids = M('zhui_pk10')->add($search);
		$dat = array();
		$arr = I('type');
		$arr2 = I('m_type');
		$vs = I('cal');

		$end = trim($search['start_num']) + $search['qishus'];
		$issue1 = array();
		for($i = trim($search['start_num']); $i < $end; $i++){
			$issue1[] = $i;
		}

		$pr = I('pours');
		$be = I('bei');
		$un = I('unit');
		$zh = I('zhong_money');
		$touzhu = I('add_money');
		$i=0;
		foreach($issue1 as $k=>$v){
			foreach($arr as $kk=>$vv){
				$dat[$i]['zhui_pk10_id'] = $ids;
				$dat[$i]['issue'] = $v;
				$dat[$i]['bei'] = $be;//多少倍
				$dat[$i]['type'] = $vv;
				$dat[$i]['m_type'] = $arr2[$kk];
				$dat[$i]['cal'] = $vs[$kk];//选择的值
				$dat[$i]['pour'] = $pr[$kk];//买了几注
				$dat[$i]['unit'] = $un[$kk];//单位
				$dat[$i]['touzhu_money'] = $touzhu[$kk];//每期投注金额
				$dat[$i]['zhong_money'] = $be * $zh[$kk];//可中金额
				$i++;
			}
		}
		$ress = M("zhui_pk10_detail")->addAll($dat);
		if($ress){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,pk10")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("pk10")->find();//上级返点
					$momm = (($c1['pk10'] - $cc['pk10'])/100) * $search['moneys'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['moneys'];
				$cp['ky_money'] = $mm['money'] - $search['moneys'];
				$cp['ctime'] = time();
				$cp['typ'] = '1';
				$cp['cid'] = $ids;
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);
			}
			echo 1;
		}else{
			echo 0;
		}
	}

	public function kl8_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("kl8")->find();
		$res = M("rebate_kl8")->find();
		$kl8 = array(
			($lv['kl8']-0)*0.08+$res['rx1'],
			($lv['kl8']-0)*0.33+$res['rx2'],
			($lv['kl8']-0)*1.44+$res['rx3mid3'],
			($lv['kl8']-0)*0.14+$res['rx3mid2'],
			($lv['kl8']-0)*6.53+$res['rx4mid4'],
			($lv['kl8']-0)*0.46+$res['rx4mid3'],
			($lv['kl8']-0)*0.09+$res['rx4mid2'],
			($lv['kl8']-0)*31.01+$res['rx5mid5'],
			($lv['kl8']-0)*1.65+$res['rx5mid4'],
			($lv['kl8']-0)*0.24+$res['rx5mid3'],
			($lv['kl8']-0)*155.06+$res['rx6mid6'],
			($lv['kl8']-0)*6.46+$res['rx6mid5'],
			($lv['kl8']-0)*0.70+$res['rx6mid4'],
			($lv['kl8']-0)*0.15+$res['rx6mid3'],
			($lv['kl8']-0)*819.58+$res['rx7mid7'],
			($lv['kl8']-0)*27.32+$res['rx7mid6'],
			($lv['kl8']-0)*2.32+$res['rx7mid5'],
			($lv['kl8']-0)*0.38+$res['rx7mid4'],
			($lv['kl8']-0)*0.17+$res['rx7mid0'],
			($lv['kl8']-0)*0.05+$res['qwsx'],
			($lv['kl8']-0)*0.10+$res['qwsxhe'],
			($lv['kl8']-0)*0.05+$res['qwjo'],
			($lv['kl8']-0)*0.10+$res['qwjohe'],
			($lv['kl8']-0)*0.08+$res['qwhezhi']
		);
		$this->assign("kl8",$kl8);
	}
	//快乐 8
	public function kl8(){
		$arr = $this->get_data2("bjkl8");
		$uid = $_SESSION['user_id'];
		if($uid){
			self::kl8_comm();
			$data = M('lottery_class')->where("id=20")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_kl8")->where("uid = $uid")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=20") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=20") ->save($d);
			}

			$da = M('lottery_class') ->where("id=20") ->find();

			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	public function adds_kl8(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'issue' => Admin_post('issue'),
			'lotteryclass' => '20',
			'pours' => Admin_post('pour'),
			'money' => Admin_post('money'),
			'numbers' => "TZ".date(md).time(),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("money")->find();
		if($mm['money'] < $search['money']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['money']);
		}
		$ids = M('lottery_kl8')->add($search);
		$dat = array();
		$arr = I('ren_type');
		$arr2 = I('ren_type2');
		$vs = I('cal');
		$pr = I('pours');
		$be = I('bei');
		$zh = I('zhong');
		foreach($arr as $k=>$v){
			$dat[$k]['lottery_kl8_id'] = $ids;
			$dat[$k]['type'] = $v;
			$dat[$k]['m_type'] = $arr2[$k];
			$dat[$k]['cal'] = $vs[$k];//选择的值
			$dat[$k]['pours'] = $pr[$k];//买了几注
			$dat[$k]['bei'] = $be[$k];//多少倍
		//	$dat[$k]['unit'] = $un[$k];//单位
			$dat[$k]['zo_money'] = $zh[$k] * $be[$k];//可中金额
		}
		$ress = M("lottery_kl8_detail")->addAll($dat);
		if($ress){
			echo 1;
		}else{
			echo 0;
		}
	}
	public function kl8_zhui_add(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'numbers' => "TZ".date(md).time(),
			'start_num' => Admin_post('issue'),
			'lotteryclass' => '20',
			'qishus' => Admin_post('qis'),
			'zhus' => Admin_post('pour'),
			'moneys' => Admin_post('money'),
			'is_ting' => Admin_post('ting'),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['moneys']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['moneys']);
		}
		$ids = M('zhui_kl8')->add($search);
		$dat = array();
		$arr = I('type');
		$arr2 = I('m_type');
		$vs = I('cal');
		
		$end = trim($search['start_num']) + $search['qishus'];
		$issue1 = array();
		for($i = trim($search['start_num']); $i < $end; $i++){
			$issue1[] = $i;
		}
		$pr = I('pours');
		$be = I('bei');
		$un = I('unit');
		$zh = I('zhong_money');
		$touzhu = I('add_money');
		$i=0;
		foreach($issue1 as $k=>$v){
			foreach($arr as $kk=>$vv){
				$dat[$i]['zhui_kl8_id'] = $ids;
				$dat[$i]['issue'] = $v;
				$dat[$i]['bei'] = $be;//多少倍
				$dat[$i]['type'] = $vv;
				$dat[$i]['m_type'] = $arr2[$kk];
				$dat[$i]['cal'] = $vs[$kk];//选择的值
				$dat[$i]['pour'] = $pr[$kk];//买了几注
				//$dat[$i]['unit'] = $un[$kk];//单位
				$dat[$i]['touzhu_money'] = $touzhu[$kk];//每期投注金额
				$dat[$i]['zhong_money'] = $be * $zh[$kk];//可中金额	
				$i++;
			}
		}
		$ress = M("zhui_kl8_detail")->addAll($dat);
		if($ress){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,kl8")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("kl8")->find();//上级返点
					$momm = (($c1['kl8'] - $cc['kl8'])/100) * $search['moneys'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['moneys'];
				$cp['ky_money'] = $mm['money'] - $search['moneys'];
				$cp['ctime'] = time();
				$cp['typ'] = '1';
				$cp['cid'] = $ids;
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);		
			}
			echo 1;
		}else{
			echo 0;
		}
	}

	public function x5_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("x11_5")->find();
		$res = M("rebate_syx5")->find();
		$x11 = array(
			($lv['x11_5']-0)*19.80+$res['smq3zhifs'],
			($lv['x11_5']-0)*0.16+$res['smq3zhids'],
			($lv['x11_5']-0)*3.30+$res['smq3zufs'],
			($lv['x11_5']-0)*3.30+$res['smq3zuds'],
			($lv['x11_5']-0)*3.30+$res['smq3zudt'],
			($lv['x11_5']-0)*2.20+$res['emq2zhifs'],
			($lv['x11_5']-0)*2.20+$res['emq2zhids'],
			($lv['x11_5']-0)*1.10+$res['emq2zufs'],
			($lv['x11_5']-0)*1.10+$res['emq2zuds'],
			($lv['x11_5']-0)*1.10+$res['emq2zudt'],
			($lv['x11_5']-0)*1.07+$res['q3ymbdw'],
			($lv['x11_5']-0)*0.22+$res['dwdfs'],
			($lv['x11_5']-0)*1.54+$res['d5s0'],
			($lv['x11_5']-0)*0.13+$res['d4s1'],
			($lv['x11_5']-0)*0.55+$res['d3s2'],
			($lv['x11_5']-0)*0.06+$res['d2s3'],
			($lv['x11_5']-0)*0.31+$res['d1s4'],
			($lv['x11_5']-0)*9.24+$res['d0s5'],
			($lv['x11_5']-0)*0.33+$res['mid03'],
			($lv['x11_5']-0)*0.14+$res['mid04'],
			($lv['x11_5']-0)*0.10+$res['mid05'],
			($lv['x11_5']-0)*0.09+$res['mid06'],
			($lv['x11_5']-0)*0.04+$res['rxfs1z1'],
			($lv['x11_5']-0)*0.11+$res['rxfs2z2'],
			($lv['x11_5']-0)*0.33+$res['rxfs3z3'],
			($lv['x11_5']-0)*0.04+$res['rxds1z1'],
			($lv['x11_5']-0)*1.32+$res['rxfs4z4'],
			($lv['x11_5']-0)*9.24+$res['rxfs5z5'],
			($lv['x11_5']-0)*1.54+$res['rxfs6z5'],
			($lv['x11_5']-0)*0.44+$res['rxfs7z5'],
			($lv['x11_5']-0)*0.16+$res['rxfs8z5'],
			($lv['x11_5']-0)*0.11+$res['rxds2z2'],
			($lv['x11_5']-0)*0.32+$res['rxds3z3'],
			($lv['x11_5']-0)*1.32+$res['rxds4z4'],
			($lv['x11_5']-0)*9.24+$res['rxds5z5'],
			($lv['x11_5']-0)*1.53+$res['rxds6z5'],
			($lv['x11_5']-0)*0.44+$res['rxds7z5'],
			($lv['x11_5']-0)*0.16+$res['rxds8z5'],
			($lv['x11_5']-0)*0.11+$res['rxdt2z2'],
			($lv['x11_5']-0)*0.33+$res['rxdt3z3'],
			($lv['x11_5']-0)*1.32+$res['rxdt4z4'],
			($lv['x11_5']-0)*9.24+$res['rxdt5z5'],
			($lv['x11_5']-0)*1.53+$res['rxdt6z5'],
			($lv['x11_5']-0)*0.44+$res['rxdt7z5'],
			($lv['x11_5']-0)*0.16+$res['rxdt8z5']
		);
		$this->assign("x11",$x11);
	}
	//广东11选5
	public function gdx5(){
		$uid = $_SESSION['user_id'];
		if($uid){
			self::x5_comm();
			$arr = $this->get_data2("gd11x5");
			$data = M('lottery_class')->where("id=22")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_11x5")->where("uid = $uid and lotteryclass=22")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=22") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=22") ->save($d);
			}
			$da = M('lottery_class') ->where("id=22") ->find();
			$end = date("Ymd")."084";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	//上海 11选5
	public function shx5(){
		$uid = $_SESSION['user_id'];
		if($uid){
			self::x5_comm();
			$arr = $this->get_data2("sh11x5");
			$data = M('lottery_class')->where("id=23")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_11x5")->where("uid = $uid and lotteryclass=23")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=23") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=23") ->save($d);
			}
			$da = M('lottery_class') ->where("id=23") ->find();
			$end = date("Ymd")."090";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	//山东 11选5
	public function sdx5(){
		self::x5_comm();
		$arr = $this->get_data2("sd11x5");
		$uid = $_SESSION['user_id'];
		$data = M('lottery_class')->where("id=24")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_11x5")->where("uid = $uid and lotteryclass=24")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=24") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=24") ->save($d);
		}
		$da = M('lottery_class') ->where("id=24") ->find();
		$end = date("Ymd")."087";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//江西 11选5
	public function jxx5(){
		self::x5_comm();
		$arr = $this->get_data2("jx11x5");
		$uid = $_SESSION['user_id'];
		$data = M('lottery_class')->where("id=25")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_11x5")->where("uid = $uid and lotteryclass=25")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=25") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=25") ->save($d);
		}
		$da = M('lottery_class') ->where("id=25") ->find();
		$end = date("Ymd")."087";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	public function x5_add(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'lotteryclass' => Admin_post('lottery_class_id'),
			'issue' => Admin_post('issue'),
			'pour' => Admin_post('pour'),
			'money' => Admin_post('money'),
			'numbers' => "TZ".date(md).time(),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['money']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['money']);
		}
		$ids = M('lottery_11x5')->add($search);
		$dat = array();
		$arr = I('type1');
		$arr2 = I('type2');
		$vs = I('cal');
		$pr = I('pours');
		$be = I('bei');
		$zh = I('zhong_money');
		foreach($arr as $k=>$v){
			$dat[$k]['lottery_11x5_id'] = $ids;
			$dat[$k]['type'] = $v;
			$dat[$k]['m_type'] = $arr2[$k];
			$dat[$k]['cal'] = $vs[$k];
			$dat[$k]['pours'] = $pr[$k];
			$dat[$k]['bei'] = $be[$k];
			$dat[$k]['zo_money'] = $zh[$k] * $be[$k];
		}
		$re = M("lottery_11x5_detail")->addAll($dat);
		if($re){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,x11_5")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("x11_5")->find();//上级返点
					$momm = (($c1['x11_5'] - $cc['x11_5'])/100) * $search['moneys'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['moneys'];
				$cp['ky_money'] = $mm['money'] - $search['moneys'];
				$cp['ctime'] = time();
				$cp['typ'] = '1';
				$cp['cid'] = $ids;
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);		
			}
			echo 1;
		}else{
			echo 0;
		}
	}
	public function x5_zhui_add(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'numbers' => "TZ".date(md).time(),
			'start_num' => Admin_post('issue'),
			'lotteryclass' => Admin_post('lotteryclass'),
			'qishus' => Admin_post('qis'),
			'zhus' => Admin_post('pour'),
			'moneys' => Admin_post('money'),
			'is_ting' => Admin_post('ting'),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['moneys']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['moneys']);
		}
		$ids = M('zhui_x5')->add($search);
		$dat = array();
		$arr = I('type');
		$arr2 = I('m_type');
		$vs = I('cal');
		$end = trim($search['start_num']) + $search['qishus'];
		$issue1 = array();
		for($i = trim($search['start_num']); $i < $end; $i++){
			$issue1[] = $i;
		}
		$pr = I('pours');
		$be = I('bei');
		$un = I('unit');
		$zh = I('zhong_money');
		$touzhu = I('add_money');
		$i=0;
		foreach($issue1 as $k=>$v){
			foreach($arr as $kk=>$vv){
				$dat[$i]['zhui_x5_id'] = $ids;
				$dat[$i]['issue'] = $v;
				$dat[$i]['bei'] = $be;//多少倍
				$dat[$i]['type'] = $vv;
				$dat[$i]['m_type'] = $arr2[$kk];
				$dat[$i]['cal'] = $vs[$kk];//选择的值
				$dat[$i]['pour'] = $pr[$kk];//买了几注
				$dat[$i]['unit'] = $un[$kk];//单位
				$dat[$i]['touzhu_money'] = $touzhu[$kk];//每期投注金额
				$dat[$i]['zhong_money'] = $be * $zh[$kk];//可中金额	
				$i++;
			}
		}
		$ress = M("zhui_x5_detail")->addAll($dat);
		if($ress){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,x11_5")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("x11_5")->find();//上级返点
					$momm = (($c1['x11_5'] - $cc['x11_5'])/100) * $search['moneys'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['moneys'];
				$cp['ky_money'] = $mm['money'] - $search['moneys'];
				$cp['ctime'] = time();
				$cp['typ'] = '1';
				$cp['cid'] = $ids;
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);		
			}
			echo 1;
		}else{
			echo 0;
		}
	}


	public function ssc_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("ssc")->find();
		$res = M("rebate_ssc")->find();
		$ssc = array(
			($lv['ssc']-0)*0.08+$res['dx2xing'],
			($lv['ssc']-0)*0.16+$res['dx3xing'],
			($lv['ssc']-0)*0.2+$res['yxingfs'],
			($lv['ssc']-0)*2+$res['exingzxfs'],
			($lv['ssc']-0)*2+$res['exingzxds'],
			($lv['ssc']-0)*2+$res['exingzxhz'],
			($lv['ssc']-0)*2+$res['exingkadu'],
			($lv['ssc']-0)*1+$res['exingzufs'],
			($lv['ssc']-0)*1+$res['exingzuds'],
			($lv['ssc']-0)*1+$res['exingzuhz'],
			($lv['ssc']-0)*1+$res['exingzubd'],
			($lv['ssc']-0)*20+$res['sxingfs'],
			($lv['ssc']-0)*20+$res['sxingds'],
			($lv['ssc']-0)*20+$res['sxingzhz'],
			($lv['ssc']-0)*20+$res['sxingkudu'],
			($lv['ssc']-0)*3.33+$res['sxingzuhe'],
			($lv['ssc']-0)*6.66+$res['sxingzu3'],
			($lv['ssc']-0)*3.33+$res['sxingzu6'],
			($lv['ssc']-0)*3.33+$res['sxinghunhe'],
			($lv['ssc']-0)*3.33+$res['sxingzubd'],
			($lv['ssc']-0)*6.66+$res['sxingzu3ds'],
			($lv['ssc']-0)*3.33+$res['sxingzu6ds'],
			($lv['ssc']-0)*0.07+$res['sxingyima'],
			($lv['ssc']-0)*0.37+$res['sxingerma'],
			($lv['ssc']-0)*2000+$res['fxingfs'],
			($lv['ssc']-0)*2000+$res['fxingds'],
			($lv['ssc']-0)*3.33+$res['fxingzu24'],
			($lv['ssc']-0)*16.66+$res['fxingzu12'],
			($lv['ssc']-0)*33.33+$res['fxingzu6'],
			($lv['ssc']-0)*50+$res['fxingzu4'],
			($lv['ssc']-0)*0.06+$res['fxingyima'],
			($lv['ssc']-0)*0.2+$res['fxingerma'],
			($lv['ssc']-0)*2000+$res['wxingfs'],
			($lv['ssc']-0)*2000+$res['wxingds'],
			($lv['ssc']-0)*16.66+$res['wxingzu120'],
			($lv['ssc']-0)*33.33+$res['wxingzu60'],
			($lv['ssc']-0)*66.66+$res['wxingzu30'],
			($lv['ssc']-0)*100+$res['wxingzu20'],
			($lv['ssc']-0)*200+$res['wxingzu10'],
			($lv['ssc']-0)*400+$res['wxingzu5'],
			($lv['ssc']-0)*0.05+$res['wxingyima'],
			($lv['ssc']-0)*0.14+$res['wxingerma'],
			($lv['ssc']-0)*0.46+$res['wxingsanma'],
			($lv['ssc']-0)*0.05+$res['wxingyifan'],
			($lv['ssc']-0)*0.25+$res['wxinghaos'],
			($lv['ssc']-0)*2.33+$res['wxingbaox'],
			($lv['ssc']-0)*43.48+$res['wxingsiji']
		);
		$pos=array_search(max($ssc),$ssc);
		$this->assign("max",$ssc[$pos]);
		$pos1=array_search(min($ssc),$ssc);
		$this->assign("min",$ssc[$pos1]);
		$this->assign("ssc",$ssc);
	}
	//重庆时时彩
	public function cqssc(){
		$uid = $_SESSION['user_id'];
		if($uid){
			self::ssc_comm();
			$arr = $this->get_data2("cqssc");
			$tim = strtotime(date("Y-m-d")." 22:00");
			$tim1 = strtotime(date("Y-m-d")." 01:55");
			if(time() > $tim){
				$we['stime'] = '22:00';
				$we['etime'] = '01:55';
				$we['jian_time'] = '5';
				$we['feng_time'] = '120';
				M('lottery_class')->where("id=15")->save($we);
			}else if(time() > $tim1){
				$we['stime'] = '10:00';
				$we['etime'] = '22:00';
				$we['jian_time'] = '10';
				$we['feng_time'] = '180';
				M('lottery_class')->where("id=15")->save($we);
			}
			$data = M('lottery_class')->where("id=15")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$ss = strtotime(date("Y-m-d")." ".$data['etime']);
			if($ss < time()){
				$s2 = date("Y-m-d",strtotime("+1 day"))." ".$data['etime'];
			}else{
				$s2 = date("Y-m-d")." ".$data['etime'];
			}
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_ssc")->where("uid = $uid and lotteryclass=15")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=15") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=15") ->save($d);
			}
			$da = M('lottery_class') ->where("id=15") ->find();
			$end = substr($da['issue'],0,8)."120";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	
	//新疆时时彩
	public function xjssc(){
		$arr = $this->get_data2("xjssc");
		$uid = $_SESSION['user_id'];
		self::ssc_comm();
		$data = M('lottery_class')->where("id=17")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		if(strtotime($data['etime']) < strtotime($data['stime'])){
			$s2 = date("Y-m-d",strtotime("+1 day"))." ".$data['etime'];
		}else{
			$s2 = date("Y-m-d")." ".$data['etime'];
		}
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
		}
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_ssc")->where("uid = $uid and lotteryclass=17")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=17") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=17") ->save($d);
		}
		$da = M('lottery_class') ->where("id=17") ->find();
		$end = substr($da['issue'],0,8)."96";
		$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
		$str = date("Ym").$days;
		$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
		$this->assign("end",$end);//最后一期
		$this->assign("str",$str);//月底
		$this->assign("ming",$ming);//明天
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}
	//天津时时彩
	public function tjssc(){
		$uid = $_SESSION['user_id'];
		if($uid){
			self::ssc_comm();
			$arr = $this->get_data2("tjssc");
			$data = M('lottery_class')->where("id=18")->find();
			$s1 = date("Y-m-d")." ".$data['stime'];
			$s2 = date("Y-m-d")." ".$data['etime'];
			if(strtotime($s1) > time() || strtotime($s2) < time()){
				$this->assign("state",1);
			}
			$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
			$ti = $jie-time();
			if($ti < 0){
				$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
				$ti = $jie-time();
			}
			$res = M("lottery_ssc")->where("uid = $uid and lotteryclass=18")->order("id desc")->limit(4)->select();
			$tt = $data['jian_time']*60-$data['feng_time'];
			if($ti < $tt){
				$d['coming_issue'] = $arr[0]['expect'];
				$d['current_issue'] = $arr[0]['expect']+1;
				M('lottery_class') ->where("id=18") ->save($d);
			}else{
				$d['coming_issue'] = $arr[0]['expect']+1;
				$d['current_issue'] = $arr[0]['expect']+2;
				M('lottery_class') ->where("id=18") ->save($d);
			}
			$da = M('lottery_class') ->where("id=18") ->find();
			$end = date("Ymd")."084";
			$days = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));
			$str = date("Ym").$days;
			$ming = date("Y-m-d",(strtotime(date("Y-m-").$days) + 3600*24));
			$this->assign("end",$end);//最后一期
			$this->assign("str",$str);//月底
			$this->assign("ming",$ming);//明天
			$this->assign("ti",$ti);
			$this->assign("arr",$arr);
			$this->assign("res",$res);
			$this->assign("dat",$da);
			$this->display();
		}
	}
	//埃及
	public function aiji(){
		$arr = $this->get_data2("ffc2");
		$uid = $_SESSION['user_id'];
		self::ssc_comm();
		$data = M('lottery_class')->where("id=19")->find();
		$jie = $data['opentimestamp']+$data['jian_time']*60-$data['feng_time'];
		$ti = $jie-time();
		if($ti < 0){
			$jie = $data['opentimestamp']+$data['jian_time']*60*2-$data['feng_time'];
			$ti = $jie-time();
		}
		$res = M("lottery_ssc")->where("uid = $uid and lotteryclass=19")->order("id desc")->limit(4)->select();
		$tt = $data['jian_time']*60-$data['feng_time'];
		if($ti < $tt){
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=19") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=19") ->save($d);
		}
		$da = M('lottery_class') ->where("id=19") ->find();
		$this->assign("ti",$ti);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}

	public function fc3d_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("fc3d")->find();
		$res = M("rebate_fc3d")->find();
		$fc3d = array(
			($lv['fc3d']-0)*0.08+$res['daxiao'],//大小
			($lv['fc3d']-0)*0.20+$res['yxfs'], //一星复式
			($lv['fc3d']-0)*2.00+$res['hou2zhix'],//后二直选
			($lv['fc3d']-0)*1.00+$res['hou2zux'],//后二组选
			($lv['fc3d']-0)*2.00+$res['qian2zhix'],//前二直选
			($lv['fc3d']-0)*1.00+$res['qian2zux'],//前二组选
			($lv['fc3d']-0)*20.00+$res['sxingzhix'],//三星直选
			($lv['fc3d']-0)*6.66+$res['sxingzux'],//三星组选
			($lv['fc3d']-0)*6.66+$res['sxingzu3'],//三星组三
			($lv['fc3d']-0)*3.33+$res['sxingzu6'],//三星组六
			($lv['fc3d']-0)*6.66+$res['sxinghunhe'],//三星混合
			($lv['fc3d']-0)*6.66+$res['sxingbd'],//三星包胆
			($lv['fc3d']-0)*6.66+$res['sxingzu3ds'],//三星组三单式
			($lv['fc3d']-0)*3.33+$res['sxingzu6ds'],//三星组六单式
			($lv['fc3d']-0)*0.07+$res['sxingyima'],//三星一码
			($lv['fc3d']-0)*0.37+$res['sxingerma']//三星二码
		);

		$this->assign("fc3d",$fc3d);
	}
	public function get_fc3dres(){
		$kaij = I("kaij");
		$arr = $this->get_data2("fc3d");
		$arr[0]['cod'] = explode(",",$arr[0]['opencode']);
		if($arr[0]['expect']==trim($kaij)){
			echo json_encode($arr[0]);
			die;
		}else{
			echo 0;
		}
	}
	//福彩3D
	public function fc3d(){
		$arr = $this->get_data2("fc3d");
		$uid = $_SESSION['user_id'];
		self::fc3d_comm();
		$data = M('lottery_class')->where("id=26")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=26") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=26") ->save($d);
		}
		$res = M("lottery_fc3d")->where("uid = $uid")->order("id desc")->limit(4)->select();
		$da = M('lottery_class') ->where("id=26") ->find();

		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}

	public function pl3_comm(){
		$uid = $_SESSION['user_id'];
		$da = M('Accountsinfo')->where("userid = '{$uid}' ")->field("yq_code")->find();
		$lv = M("agent")->where("code = '{$da['yq_code']}'")->field("pl3_5")->find();
		$res = M("rebate_pl3")->find();
		$pl3 = array(
			($lv['pl3_5']-0)*0.08+$res['daxiao'],
			($lv['pl3_5']-0)*0.20+$res['yxfs'],
			($lv['pl3_5']-0)*2.00+$res['hou2zhix'],
			($lv['pl3_5']-0)*1.00+$res['hou2zux'],
			($lv['pl3_5']-0)*2.00+$res['qian2zhix'],
			($lv['pl3_5']-0)*1.00+$res['qian2zux'],
			($lv['pl3_5']-0)*20.00+$res['sxingzhix'],
			($lv['pl3_5']-0)*6.66+$res['sxingzux'],
			($lv['pl3_5']-0)*6.66+$res['sxingzu3'],
			($lv['pl3_5']-0)*3.33+$res['sxingzu6'],
			($lv['pl3_5']-0)*6.66+$res['sxinghunhe'],
			($lv['pl3_5']-0)*6.66+$res['sxingbd'],
			($lv['pl3_5']-0)*6.66+$res['sxingzu3ds'],
			($lv['pl3_5']-0)*3.33+$res['sxingzu6ds'],
			($lv['pl3_5']-0)*0.07+$res['sxingyima'],
			($lv['pl3_5']-0)*0.37+$res['sxingerma']
		);
		$this->assign("pl3",$pl3);
	}
	public function get_pl3res(){
		$kaij = I("kaij");
		$arr = $this->get_data2("pl3");
		$arr[0]['cod'] = explode(",",$arr[0]['opencode']);
		if($arr[0]['expect']==trim($kaij)){
			echo json_encode($arr[0]);
			die;
		}else{
			echo 0;
		}
	}
	//排列3
	public function pl3(){
		$arr = $this->get_data2("pl3");
		$uid = $_SESSION['user_id'];
		self::pl3_comm();
		$data = M('lottery_class')->where("id=27")->find();
		$s1 = date("Y-m-d")." ".$data['stime'];
		$s2 = date("Y-m-d")." ".$data['etime'];
		if(strtotime($s1) > time() || strtotime($s2) < time()){
			$this->assign("state",1);
			$d['coming_issue'] = $arr[0]['expect']+1;
			$d['current_issue'] = $arr[0]['expect']+2;
			M('lottery_class') ->where("id=27") ->save($d);
		}else{
			$d['coming_issue'] = $arr[0]['expect'];
			$d['current_issue'] = $arr[0]['expect']+1;
			M('lottery_class') ->where("id=27") ->save($d);
		}
		$res = M("lottery_kl8")->where("uid = $uid")->order("id desc")->limit(4)->select();
		$da = M('lottery_class') ->where("id=27") ->find();
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("dat",$da);
		$this->display();
	}














	//添加时时彩
	public function ssc_add(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'lotteryclass' => Admin_post('lotteryclass'),
			'issue' => Admin_post('issue'),
			'pour' => Admin_post('pour'),
			'money' => Admin_post('money'),
			'numbers' => "TZ".date(md).time(),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['money']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['money']);
		}
		$ids = M('lottery_ssc')->add($search);
		$dat = array();
		$arr = I('type');
		$arr2 = I('m_type');
		$vs = I('cal');
		$pr = I('pours');
		$be = I('bei');
		$zh = I('zhong_money');
		foreach($arr as $k=>$v){
			$dat[$k]['lottery_ssc_id'] = $ids;
			$dat[$k]['type'] = $v;
			$dat[$k]['m_type'] = $arr2[$k];
			$dat[$k]['cal'] = $vs[$k];//选择的值
			$dat[$k]['pours'] = $pr[$k];//买了几注
			$dat[$k]['bei'] = $be[$k];//多少倍
			$dat[$k]['zo_money'] = $zh[$k] * $be[$k];//可中金额
		}
		$re = M("lottery_ssc_detail")->addAll($dat);
		if($re){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,ssc")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("ssc")->find();//上级返点
					$momm = (($c1['ssc'] - $cc['ssc'])/100) * $search['money'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['money'];
				$cp['ky_money'] = $mm['money'] - $search['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);
			}
			echo 1;
		}else{
			echo 0;
		}
	}
	//追号时时彩
	public function ssc_zhui_add(){
		$search = array(
			'uid' => $_SESSION['user_id'],
			'numbers' => "TZ".date(md).time(),
			'start_num' => Admin_post('issue'),
			'lotteryclass' => Admin_post('lotteryclass'),
			'qishus' => Admin_post('qis'),
			'zhus' => Admin_post('pour'),
			'moneys' => Admin_post('money'),
			'is_ting' => Admin_post('ting'),
			'ctime' => time()
		);
		$mm = M('Accountsinfo')->where("userid = '{$search['uid']}'")->field("yq_code,money")->find();
		if($mm['money'] < $search['moneys']){
			echo 3;die;
		}else{
			M('Accountsinfo')->where("userid = '{$search['uid']}'")->setDec('money',$search['moneys']);
		}
		$ids = M('zhui_ssc')->add($search);
		$dat = array();
		$arr = I('type');
		$arr2 = I('m_type');
		$vs = I('cal');
		$end = trim($search['start_num']) + $search['qishus'];
		$issue1 = array();
		for($i = trim($search['start_num']); $i < $end; $i++){
			$issue1[] = $i;
		}
		$pr = I('pours');
		$be = I('bei');
		$un = I('unit');
		$zh = I('zhong_money');
		$touzhu = I('add_money');
		$i=0;
		foreach($issue1 as $k=>$v){
			foreach($arr as $kk=>$vv){
				$dat[$i]['zhui_ssc_id'] = $ids;
				$dat[$i]['issue'] = $v;
				$dat[$i]['bei'] = $be;//多少倍
				$dat[$i]['type'] = $vv;
				$dat[$i]['m_type'] = $arr2[$kk];
				$dat[$i]['cal'] = $vs[$kk];//选择的值
				$dat[$i]['pour'] = $pr[$kk];//买了几注
			//	$dat[$i]['unit'] = $un[$kk];//单位
				$dat[$i]['touzhu_money'] = $touzhu[$kk];//每期投注金额
				$dat[$i]['zhong_money'] = $be * $zh[$kk];//可中金额	
				$i++;
			}
		}
		$ress = M("zhui_ssc_detail")->addAll($dat);
		if($ress){
			if($mm['yq_code']){
				$cc = M("agent")->where("code = '{$mm['yq_code']}'")->field("uid,ssc")->find();//上级id  我的返点
				if($cc['uid']!='0'){
					$tr = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("yq_code")->find();
					$c1 = M("agent")->where("code = '{$tr['yq_code']}'")->field("ssc")->find();//上级返点
					$momm = (($c1['ssc'] - $cc['ssc'])/100) * $search['moneys'];
					M('Accountsinfo')->where("userid = '{$cc['uid']}'")->setInc('money',$momm);//上级增加
					$yy = M('Accountsinfo')->where("userid = '{$cc['uid']}'")->field("money")->find();
					$cp1['number'] = date("Ymd").rand(100000,999999);
					$cp1['type'] = '4';
					$cp1['shou_money'] = $momm;
					$cp1['ky_money'] = $yy['money'];
					$cp1['ctime'] = time();
					$cp1['uid'] = $cc['uid'];
					$cp1['remark'] = '投注返点';
					M("jiaoyi")->add($cp1);
				}
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '3';
				$cp['zhi_money'] = $search['moneys'];
				$cp['ky_money'] = $mm['money'] - $search['moneys'];
				$cp['ctime'] = time();
				$cp['typ'] = '1';
				$cp['cid'] = $ids;
				$cp['uid'] = $search['uid'];
				$cp['remark'] = '投注扣款';
				M("jiaoyi")->add($cp);		
			}
			echo 1;
		}else{
			echo 0;
		}
	}















}